package spring

import (
	"reflect"

	"github.com/go-spring/spring-core/gs"
	"github.com/meilihao/golib/v2/log"
)

var (
	GlobalApplicationContext gs.Container = gs.New()
	GlobalMyContainer        *MyContainer = NewMyContainer()
)

func NewApplicationContext() gs.Container {
	return GlobalApplicationContext
}

func Register(i interface{}, id string, exts []*PluginExtension) {
	beanDef := GlobalApplicationContext.Object(i)
	if id == "" {
		id = beanDef.Type().Elem().Name()
	}

	if id == "" {
		log.Glog.Panic("empty id")
	}

	GlobalMyContainer.Object(i, beanDef, id, exts)
}

func RegisterInterface(id string, t reflect.Type) {
	if id == "" {
		log.Glog.Panic("empty id")
	}

	GlobalMyContainer.RegisterInterface(id, t)
}
